package gengine.common.packets.server;

import gengine.common.packets.BasePacket;
import gengine.common.packets.PacketParsingException;
import gengine.common.packets.PacketTypeEnum;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * User: arseniy
 * Date: 21.12.11
 */
public class InitPacket extends BasePacket {
    String text;

    public InitPacket(){
        super();
    }

    public InitPacket(String text,int id) {
        super(id);
        this.text = text;
    }

    @Override
    public PacketTypeEnum getPacketType() {
        return PacketTypeEnum.ServerInitPacket;
    }

    @Override
    protected void writeCore(ObjectOutputStream stream) throws IOException {
        stream.writeObject(text);
    }

    @Override
    protected void readCore(ObjectInputStream stream) throws IOException {
        try {
            text = (String) stream.readObject();
        } catch (ClassNotFoundException e) {
            new PacketParsingException(e);
        }
    }

    public String getText() {return text;}
}
